// ---------------------------------------------------------------------
//
// -- 六边形item
// -- author £
//
// ---------------------------------------------------------------------

const Y_UP = 110;

cc.Class({
    extends: cc.Component,

    properties: {
        selected: false,
        sfs: {
            default: [],
            type: cc.SpriteFrame
        }
    },

    ctor: function () {
        this._firstNode = null;
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.node.scaleX = this.node.scaleY = this.selected ? 1 : 0.7;
    },

    start () {

    },

    getFisrtLocation: function () {
        return {
            x: this._firstNode.x,
            y: this._firstNode.y
        }
    },

    setData: function (data) {
        let i, locations = data.nodeLocation, 
            len = locations.length,
            node, sp;

        this.node.removeAllChildren();

        for (i = 0; i < len; ++i) {
            node = new cc.Node();
            this.node.addChild(node);

            if (i === 0) this._firstNode = node;

            sp = node.addComponent(cc.Sprite);
            sp.spriteFrame = this.sfs[data.colorIndex];
            // node.color = data.color;
            node.x = locations[i].x;
            node.y = locations[i].y;

            if (this.selected) {
                node.y += Y_UP;
            }
        }
    },

    // update (dt) {},
});
